# include "serialib.h"
# include "serial_player.h"

int main(int argc, char* argv[]) 
{
    std::string virtualTx = "/tmp/virtual_tx";
    std::string virtualRx = "/tmp/virtual_rx";
    unsigned int baudRate = 115200;
    std::string logFile;
    
    if (argc < 4) {
        std::cerr << "用法: " << argv[0] << " <日志文件> [波特率] [端口名称]" << std::endl;
        return 1;
    }

    logFile = argv[1];
    try 
    { 
        baudRate = std::stoi(argv[2]); 
    } 
    catch (...) 
    { 
        std::cerr << "无效的波特率，使用默认值: " << baudRate << std::endl; 
    }
    std::string virtualPort = argv[3];
    virtualTx = virtualPort + "_tx";
    virtualRx = virtualPort;

    serial_player m_player(virtualTx, virtualRx, baudRate, logFile);
    auto startTime = std::chrono::high_resolution_clock::now();
    double prevTimestamp = m_player.getFirstTimestamp();
    m_player.play(startTime, prevTimestamp);
} 